package com.yoomiito.app.adapter.my;

import androidx.annotation.Nullable;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yoomiito.app.Constant;
import com.yoomiito.app.R;
import com.yoomiito.app.model.my.MyInviteBean;
import com.yoomiito.app.utils.ImageLoader;
import com.yoomiito.app.utils.Type;
import com.yoomiito.app.widget.CircleImageView;

import java.util.List;

public class MyInviteAdapter extends BaseQuickAdapter<MyInviteBean.DataBean, BaseViewHolder> {

    private int type;

    public MyInviteAdapter(@Nullable List<MyInviteBean.DataBean> data, int type) {
        super(R.layout.item_my_invite, data);
        this.type = type;
    }

    @Override
    protected void convert(final BaseViewHolder helper, MyInviteBean.DataBean item) {
        ImageView sddIv = helper.getView(R.id.userFlagIv);
        sddIv.setVisibility(item.getThree_role_id() >= Type.LevelType.SDD_VIP_10 && type == Constant.USER_TYPE_VIP ? View.VISIBLE : View.GONE);
        if (item.getThree_role_id() >= 10 && item.getThree_role_id() < 20) {
            sddIv.setImageResource(R.drawable.sdd__flag_red_10);
        } else if (item.getThree_role_id() >= 20 && item.getThree_role_id() < 30) {
            sddIv.setImageResource(R.drawable.sdd__flag_red_20);

        } else if (item.getThree_role_id() >= 30 && item.getThree_role_id() < 40) {
            sddIv.setImageResource(R.drawable.sdd__flag_red_30);

        } else if (item.getThree_role_id() >= 40) {
            sddIv.setImageResource(R.drawable.sdd__flag_red_40);
        }


        helper.addOnClickListener(R.id.userFlagIv);
        RequestOptions requestOptions = new RequestOptions();
        requestOptions.placeholder(R.drawable.goods_default);
        CircleImageView circleImageView = helper.getView(R.id.iv_photo);
        helper.setText(R.id.mobile, item.getMobile());
        if (!TextUtils.isEmpty(item.getHeadimgurl())) {
//            Glide.with(App.getApplication()).load(Uri.parse(item.getHeadimgurl())).apply(requestOptions).into(circleImageView);
            ImageLoader.getInstance().into(circleImageView.getContext(), item.getHeadimgurl(), circleImageView);
        } else {
            circleImageView.setImageResource(R.drawable.wo_no);
        }
        TextView nameTv = helper.getView(R.id.tv_name);
        nameTv.setText(item.getNickname());
        nameTv.requestLayout();

//        if (Constant.USER_TYPE_VIP == type || Constant.USER_TYPE_SDD_VIP == type) {
//            TextView tv = helper.getView(R.id.tv_regist_time);
//            if (TextUtils.isEmpty(item.getCtime())) {
//                tv.setVisibility(View.GONE);
//            } else {
//                tv.setVisibility(View.VISIBLE);
//                tv.setText("升级日期:" + item.getCtime());
//            }
//        } else {
//            ((TextView) helper.getView(R.id.tv_regist_time)).setText("注册日期:" + item.getCtime());
//        }
        ((TextView) helper.getView(R.id.tv_regist_time)).setText("注册日期:" + item.getCtime());

        if (!TextUtils.isEmpty(item.getLast_login_date()))
            ((TextView) helper.getView(R.id.tv_login_time)).setText("最近登录时间:" + item.getLast_login_date());
        else{
            ((TextView) helper.getView(R.id.tv_login_time)).setText(":");
        }
        ((TextView) helper.getView(R.id.tv_num)).setText("" + item.getTt());
        helper.addOnClickListener(R.id.copy);
    }
}
